home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / Color Window Demo / Main color.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-30  |  3.9 KB  |  131 lines  |  [TEXT/KAHL]

  1. /*
  2.         Color Window Demonstration Program
  3.         By:    Jim Griffin
  4.             Indianapolis, IN
  5.             IJDG400 @ Indycms.bitnet.edu
  6.             JimGriffin on America On Line
  7.             
  8.         Copyright © 1990 by Jim Griffin
  9.         
  10.         This program may not be sold or given away for profit.
  11.         Feel free to distribute the program and source code among your friends,
  12.         but all files must be included in the exchange.
  13.         Keep all the files together.
  14.         All rights reserved.
  15.             
  16.  
  17.  
  18. I wrote this program to teach myself about intricacies of creating color windows, and color controls.
  19. I don't claim that this program demonstrates the best method of creating and displaying 
  20. color windows merely that this is one of the ways.  Feel free to use the knowledge 
  21. you learn here in other programs you may write.  My only desire is that you will 
  22. release your code so that others may also gain new knowledge in programing Macintosh 
  23. computers.
  24.  
  25. To create this program I made extensive modifications to the code from 
  26. the "ShowOff" source code in the Developer's Source Code library that 
  27. is in America Online.
  28.  
  29.  
  30.     NOTE: I assume that you will have a copy of Inside Macintosh Vols 1 thru 5 handy.
  31.             If not then you might have difficulty understanding some of the color
  32.             routines such as GetColor();, GetAuxWin(aWindow, &some_new_colors);, and
  33.             all the rest.
  34.             I also assume that you will understand C statements that look like
  35.  
  36.             (**(**some_new_colors).awCTable).ctTable[0].value = 0;
  37.  
  38.             If the above statement makes your eyes cross, then perhaps this program 
  39.             isn't for you.  On the other hand if you want to learn how use statements
  40.             like that then you should try to read the program.
  41. */
  42.  
  43. /*        WARNING:  Inside Mac Vol 5 document bug! 
  44.              Inside Mac Vol 5 on page 207 defines GetAuxWin as returning a CTabHandle,
  45.             This is wrong, it really returns an AuxWinHandle!!!!  this drove me crazy for
  46.             an hour before I realized that it didn't make since for GetAuxWin to return
  47.             a CTabHandle. It made more sense for it to return an AuxWinHandle. (Note 
  48.             the AuxWin in both words)  Some quick experimenting with the Think C 
  49.             source Code Debugger proved this to  be correct!  
  50.             P.S. If you believe Inside Mac and treat GetAuxWin as returning a CTabHandle
  51.             you will notice that your program will do strange things and then 
  52.             really bomb!
  53. */
  54.  
  55.  
  56. #include "my color.h"
  57.  
  58. main()                    /*main program*/
  59. {
  60. CWindowPtr    who_is_in_front;
  61.  
  62.     init_color_demo();            /* initialize the Managers, prepare for program execution */
  63.     OpenWindow();                /*start with one open window*/
  64.  
  65. /* Main event loop */
  66.     do
  67.     {
  68.         SystemTask();
  69.         who_is_in_front = (CWindowPtr)FrontWindow();
  70.         if (who_is_in_front != nil)
  71.             if ((*(CWindowPeek)who_is_in_front).windowKind >= 0)
  72.                 FixCursor();
  73.  
  74.         if (!menusOK && (who_is_in_front == nil))
  75.         {
  76.             DisableItem (myMenus [fileM], closeItem);
  77.             DisableItem (myMenus [editM], 0);
  78.             menusOK = true;
  79.         }
  80.         if (textH != nil)
  81.              TEIdle(textH);
  82.         if (GetNextEvent(everyEvent,&myEvent))
  83.             switch (myEvent.what) 
  84.             {
  85.  
  86.                 case mouseDown:
  87.                     do_mouse_down(&myEvent);
  88.                     break;
  89.                 case keyDown:
  90.                 case autoKey:
  91.                         if ((myEvent.modifiers & cmdKey) != 0)
  92.                             DoCommand(MenuKey(myEvent.message & charCodeMask));
  93.                         else TEKey((char)(myEvent.message & charCodeMask),textH);
  94.                         break;
  95.                         
  96.                 case activateEvt:
  97.                     do_activate(&myEvent);
  98.                     break;
  99.                     
  100.                 case updateEvt:
  101.                     do_update(&myEvent);
  102.                     break;
  103.  
  104.             }    /*switch myEvent.what*/
  105.  
  106.     }
  107.     while (!doneFlag);
  108.     
  109.     return;
  110. } /*end of the main program modual*/
  111.  
  112.             
  113.  
  114. FixCursor()    /* make the cursor an I-Beam when over the content of our active window */
  115.             /* else make the cursor an Arrow */
  116. {
  117. Point    mouseLoc;
  118. Rect    test_rect;
  119.  
  120.     GetMouse (&mouseLoc);
  121.     test_rect = thePort->portRect;
  122.     test_rect.right = test_rect.right - BAR_WIDTH;        /* don't forget about the scroll bars */
  123.     test_rect.bottom = test_rect.bottom - BAR_WIDTH;
  124.     
  125.     if (PtInRect (mouseLoc, &test_rect))
  126.          SetCursor(*(GetCursor(iBeamCursor)));
  127.     else
  128.         SetCursor(&arrow);
  129. }
  130.  
  131.